package HBase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.*;

import java.io.IOException;
import java.sql.*;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Properties;

/**
 * Created by Zhou_Bing on 2019/3/28.
 */
public class PhoenixManager {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
        //Connection con = DriverManager.getConnection("jdbc:phoenix:sdc67.sefonsoft.com,sdc68.sefonsoft.com,sdc69.sefonsoft.com,sdc70.sefonsoft.com,sdc71.sefonsoft.com:2181");
        Connection con = DriverManager.getConnection("jdbc:phoenix:10.20.69.71:2181");
        System.out.println(con);
        Statement stmt = con.createStatement();
//        ResultSet rs = stmt.executeQuery("select * from eqm_repair_workorder limit 0 offset 10");
//        stmt.execute("delete from eqm_repair_workorder");
        stmt.execute("ALTER TABLE EQM_SHUTDOWN_NOTICE DROP COLUMN TASK_ID");


//        stmt.execute("delete from eqm_maintain_workorder where ID <=5820369 and ID >=5797263");
//        ResultSet rs = stmt.executeQuery("select * from eqm_maintain_workorder limit 0,10");
//        stmt.execute("ALTER TABLE eqm_maintain_workorder ADD orgseq varchar");
//        stmt.execute("UPSERT INTO eqm_maintain_workorder(id,orgseq ) SELECT t1.id, t2.orgseq FROM eqm_maintain_workorder t1 INNER JOIN link_org t2 on(t1.sta_org_code = t2.org_code) where t1.ID <="+max+" and ID >= "+i);
//        con.commit();
//        rs.next();
//        System.out.println("########"+rs.getInt(1)+"########");


//        deleteAll();
    }

    public static void deleteAll() throws ClassNotFoundException, SQLException {
        int minId=0,maxId = 6006231;
        for(int start=minId;start<=maxId;start+=100000){
            int end = start + 99999;
            if(end>maxId){
                end = maxId;
            }
            Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
            Connection con = DriverManager.getConnection("jdbc:phoenix:10.20.69.71:2181");
            System.out.println(con);
            Statement stmt = con.createStatement();
            stmt.execute("delete from eqm_maintain_workorder where ID <="+end+" and ID >="+start);
            con.commit();
            System.out.println("删除:"+start+"~~~~~~~"+end);
        }
        System.out.println("全部删除结束");
    }
}
